package com.nulldev.util.security.encryptAPI;

import com.nulldev.util.JVM.JVM;
import com.nulldev.util.VariableAPI.ArrayUtils;
import com.nulldev.util.VariableAPI.RandomUtil;
import com.nulldev.util.io.FastIO.FastIO;
import com.nulldev.util.security.encryptAPI.Encryptors.SystemEncryptors;

public class EncryptorAPIDemo {

	public static void main(String[] args) {
		JVM.println("EncryptorAPI v1.0.1 - for nullUtil 3.0");
		JVM.println("Printing registered encryptors...");
		FastIO.get().flush();
		ArrayUtils.printLln(SystemEncryptors.values());
		JVM.println("Attempting to simulate encryption on all encryptors.");
		final String key = RandomUtil.hexString(32);
		final String payload = "here is a odd string lol";
		JVM.println("Key: " + new String(key));
		JVM.println("Payload: " + payload + " (length: " + payload.length() + ")");
		for (final SystemEncryptors encryptor : SystemEncryptors.values()) {
			try {
				final String output = Encryptors.encryptorFor(encryptor, key, 2).encrypt(payload);
				final String dec = Encryptors.encryptorFor(encryptor, key, 2).decrypt(output);
				JVM.println(encryptor + ": ");
				JVM.println("\tOutput: " + output);
				JVM.println("\tDecoded: " + dec);
				JVM.println("\tEqual?: " + (dec.contentEquals(payload)) + " (working: " + !(output.equals(payload)) + ")");
			} catch (Exception e) {
				JVM.println("Failed to run: " + encryptor);
				JVM.errorln(e);
			}
		}
	}

}
